package com.zjs.swagger2.demo.web;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zjs.swagger2.demo.domain.User;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Api(value="Swagger2学习举例")
@RestController
public class SwaggerController {
	
	@ApiOperation(value = "按ID查询", notes = "返回String结果") 
	@RequestMapping(value = "/findByID", method = RequestMethod.POST)
	public String findByID(@ApiParam(value = "编号", required = true) @RequestParam String id){
		return "findByID Swagger2   "+id;
	}
	
	@ApiOperation(value = "按ID查询2", notes = "返回String结果") 
	@RequestMapping(value = "/findByID/{id}", method = RequestMethod.POST)
	public String findByID2(@ApiParam(value = "编号", required = true) @PathVariable String id){
		return "findByID Swagger2   "+id;
	}
	
	@ApiOperation(value = "按ID和Name查询", notes = "返回String结果") 
	@RequestMapping(value = "/findByIDAndName", method = RequestMethod.POST)
	public String findByIDAndName(@ApiParam(value = "编号", required = true) @RequestParam String id,@ApiParam(value = "名称") @RequestParam String name){
		return "findByID Swagger2   "+id+name;
	}
	
	
	@ApiOperation(value = "按USER查询", notes = "返回User结果",httpMethod="POST")
   // @ApiImplicitParam(name = "user", value = "user实体", required = true, dataType = "User")    
	@RequestMapping(value = "/findByUser", method = RequestMethod.POST)
	public User findByUser(@ApiParam(value = "user实体", required = true) @RequestBody User user){
		return user;
	}
	
	@ApiOperation(value = "按List查询", notes = "返回list结果",httpMethod="POST")
	   // @ApiImplicitParam(name = "user", value = "user实体", required = true, dataType = "User")    
	@RequestMapping(value = "/findByList", method = RequestMethod.POST)
	public List<User> findByList(@ApiParam(value = "user list", required = true) @RequestBody List<User> list){
		return list;
	}
	
	
	@ApiOperation(value = "按ID和实体查询", notes = "返回USER结果") 
	@RequestMapping(value = "/findByIDAndUser", method = RequestMethod.POST)
	public User findByIDAndUser(@ApiParam(value = "编号", required = true) @RequestParam String id,@ApiParam(value = "实体") @RequestBody User user){
		user.setId(id);
		return user;
	}
	
	@ApiOperation(value = "按ID和实体查询", notes = "返回USER结果") 
	@ApiImplicitParams({
        @ApiImplicitParam(paramType="query",name ="id" , value = "用户ID", required = true, dataType = "String"),
        @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
	})
	 @ApiResponses({@ApiResponse(
	            code = 400,
	            message = "请求处理失败404"
	    ), @ApiResponse(
	            code = 404,
	            message = ""
	    )})
	@RequestMapping(value = "/findByIDAndUser2", method = RequestMethod.POST)
	public User findByIDAndUser2(@RequestParam String id,@RequestBody User user){
		user.setId(id);
		return user;
	}
	
	@ApiOperation(value = "按map查询", notes = "返回map结果",httpMethod="POST")
	@RequestMapping(value = "/findByMap", method = RequestMethod.POST)
	public Map<String,Object> findByMap(@ApiParam(value = "map", required = true) @RequestBody Map<String,Object> map){
		return map;
	}
	

}
